<?php

namespace app\command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;


class AutoHideRule extends Command
{
    protected static $defaultName = 'autoHide:rule';
    protected static $defaultDescription = 'AutoHideRule';

    /**
     * @return void
     */
    protected function configure()
    {
        $this->addArgument('name', InputArgument::OPTIONAL, 'Name description');
    }

    /**
     * @param InputInterface $input
     * @param OutputInterface $output
     * @return int
     */
    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $name = $input->getArgument('name');

        $rules = \plugin\admin\app\model\Rule::where('pid', '<>', 0)->get()->toArray();

        foreach ($rules as $rule) {
            $pr = \plugin\admin\app\model\Rule::where('id', $rule['pid'])->first();
            if ($pr['is_show'] == 0) {
                \plugin\admin\app\model\Rule::where('id', $rule['id'])->update(['is_show' => 0]);
            }
        }

        return self::SUCCESS;
    }

}
